package com.ttbj.controller.webuser;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ttbj.api.dto.Page;
import com.ttbj.api.dto.webuser.WebUserDto;
import com.ttbj.api.exception.BusinessException;
import com.ttbj.api.webuser.WebUserService;
import com.ttbj.util.ViewDataUtil;


@Controller
public class WebUserController {
	
	@Autowired
	private WebUserService webUserService;
	
	
	/**
	 * 兔兔搬家微信用户列表页面
	 * @return
	 */
	@RequestMapping("/webuser/web_user_list.htm")
	public String web_user_list() {
		return "webuser/web_user_list";
	}
	
	
	/**
	 * 查询兔兔搬家微信所有没被删除的用户的详细信息
	 * @param request
	 * @param page 分页
	 * @param webUserDto 用户信息
	 * @return
	 */
	@RequestMapping(value="/webuser/getWebUserByPage.htm", method=RequestMethod.POST, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String getWebUserByPage(HttpServletRequest request, Page page, WebUserDto webUserDto) {
		try {
			List<WebUserDto> webUserDtoList = this.webUserService.findWebUserByPage(page, webUserDto);
			int count = 0;
			if (null != webUserDtoList) {
				count = this.webUserService.findWebUserByPageCount(webUserDto);
			}
			return ViewDataUtil.buildSuccessPageJson("用户管理", webUserDtoList, count);
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
}
